import {
  addWords,
  createEnterprise,
  createLink,
  delSeo, delWords,
  seoAudit,
  seoForbid,
  seoInfo,
  seoQuery,
  seoSummary, sum_global,
  sum_main, wordCheck, wordKind, wordsList
} from "../../api/summary"
import {trace} from "../../utils/trace"
import {getToken} from "../../utils/auth"

const getDefaultState = () => {
  return {
    token: getToken(),
    name: '',
    avatar: ''
  }
}

const state = getDefaultState()

const mutations = {
  RESET_STATE: (state) => {
    Object.assign(state, getDefaultState())
  },
  SET_TOKEN: (state, token) => {
    state.token = token
  },
  SET_NAME: (state, name) => {
    state.name = name
  },
  SET_AVATAR: (state, avatar) => {
    state.avatar = avatar
  }
}

const actions = {
  // 获取概况整体数据
  sum_main({ commit, state }) {
    return new Promise((resolve, reject) => {
      sum_main(state.token).then(response => {
        const { data } = response
        resolve(data)
      }).catch(error => {
        reject(error)
      })
    })
  },
  // 获取概况整体数据 --管理人
  sum_global({ commit, state }) {
    return new Promise((resolve, reject) => {
      sum_global(state.token).then(response => {
        const { data } = response
        resolve(data)
      }).catch(error => {
        reject(error)
      })
    })
  },
  // 获取概况整体数据
  seoInfo({ commit, state },data) {
    return new Promise((resolve, reject) => {
      seoInfo(data).then(response => {
        const { data } = response
        resolve(data)
      }).catch(error => {
        reject(error)
      })
    })
  },
  // 删除推广信息
  delSeo({ commit, state },data) {
    return new Promise((resolve, reject) => {
      delSeo(data).then(response => {
        const { data } = response
        resolve(data)
      }).catch(error => {
        reject(error)
      })
    })
  },
  //获取推广列表
  seoQuery({ commit, state },data) {
    return new Promise((resolve, reject) => {
      seoQuery(data).then(response => {
        const { data } = response
        resolve(data)
      }).catch(error => {
        reject(error)
      })
    })
  },
  //获取推广数据的总结
  seoSummary({ commit, state },data) {
    return new Promise((resolve, reject) => {
      seoSummary(data).then(response => {
        const { data } = response
        resolve(data)
      }).catch(error => {
        reject(error)
      })
    })
  },
  //禁止推广服务
  seoForbid({ commit, state },data) {
    return new Promise((resolve, reject) => {
      seoForbid(data).then(response => {
        const { data } = response
        resolve(data)
      }).catch(error => {
        reject(error)
      })
    })
  },
  //管理员审核服务
  seoAudit({ commit, state },data) {
    return new Promise((resolve, reject) => {
      seoAudit(data).then(response => {
        const { data } = response
        resolve(data)
      }).catch(error => {
        reject(error)
      })
    })
  },

  //新建服务推广
  createLink({ commit, state },data) {
    return new Promise((resolve, reject) => {
      createLink(data).then(response => {
        const { data } = response
        resolve(data)
      }).catch(error => {
        reject(error)
      })
    })
  },

  //新建企业推广
  createEnterprise({ commit, state },data) {
    return new Promise((resolve, reject) => {
      createEnterprise(data).then(response => {
        const { data } = response
        resolve(data)
      }).catch(error => {
        reject(error)
      })
    })
  },
  //违禁词-检查
  wordCheck({ commit, state },data) {
    return new Promise((resolve, reject) => {
      wordCheck(data).then(response => {
        const { data } = response
        resolve(data)
      }).catch(error => {
        reject(error)
      })
    })
  },
   //违禁词库-列表
  wordsList({ commit, state },data) {
    return new Promise((resolve, reject) => {
      wordsList(data).then(response => {
        const { data } = response
        resolve(data)
      }).catch(error => {
        reject(error)
      })
    })
  },
    //违禁词库-更改使用范围
  wordKind({ commit, state },data) {
    return new Promise((resolve, reject) => {
      wordKind(data).then(response => {
        const { data } = response
        resolve(data)
      }).catch(error => {
        reject(error)
      })
    })
  },
  //违禁词库-删除
  delWords({ commit, state },data) {
    return new Promise((resolve, reject) => {
      delWords(data).then(response => {
        const { data } = response
        resolve(data)
      }).catch(error => {
        reject(error)
      })
    })
  },
  //违禁词库-新增
  addWords({ commit, state },data) {
    return new Promise((resolve, reject) => {
      addWords(data).then(response => {
        const { data } = response
        resolve(data)
      }).catch(error => {
        reject(error)
      })
    })
  },




}

export default {
  namespaced: true,
  state,
  mutations,
  actions
}

